﻿#region Copyright
//————————————————————————————————————————//
//	创建人员(Creator)    ：Huangyd
//	创建日期(Date)       ：2012-08-05
//  联系方式(Email)      ：aj-ayumi@163.com; gajayumi@gmail.com; ajayumi@me.com
//  描    述(Description)：
//
//	Copyright (C) 2012 ajayumi 版权所有
//————————————————————————————————————————//
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace ajayumi.Platform.WinForm.WorkSpace
{
    /// <summary>
    /// 工作空间的基础对象
    /// </summary>
    public abstract class WorkSpaceBase : IDisposable
    {
        #region Properties

        private ContainerControl m_ContainerCtrl = null;

        //private IMainForm m_FrmMain = null;
        //public IMainForm ParentFormMain
        //{
        //    get { return m_FrmMain; }
        //    set
        //    {
        //        if (m_FrmMain != null) return;
        //        m_FrmMain = value;
        //    }
        //}

        /// <summary>
        /// 主容器
        /// </summary>
        public IParentContainer ParentContainer { get; set; }

        /// <summary>
        /// 名称，作为唯一标识
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 容器控件
        /// </summary>
        public ContainerControl ContainerCtrl
        {
            get
            {
                if (this.m_ContainerCtrl == null || this.m_ContainerCtrl.IsDisposed)
                {
                    this.m_ContainerCtrl = this.InitContainerCtrl();
                }
                return this.m_ContainerCtrl;
            }
        }

        /// <summary>
        /// 是否销毁控件，默认情况下为True
        /// </summary>
        public bool IsDisposeControl { get; private set; }

        #endregion

        public WorkSpaceBase(string name)
            : this(name, true)
        {
        }

        public WorkSpaceBase(string name, bool isDisposePnl)
        {
            Console.WriteLine("{0} {1}被实例化", DateTime.Now, this.ToString());
            this.Name = name;
            this.IsDisposeControl = isDisposePnl;
        }

        /// <summary>
        /// 初始化工具条项
        /// </summary>
        public abstract ToolStripItem[] InitToolStripItems { get; }

        /// <summary>
        /// 初始化容器控件（子容器）
        /// </summary>
        /// <returns></returns>
        protected abstract ContainerControl InitContainerCtrl();

        /// <summary>
        /// 注册事件
        /// </summary>
        public abstract void RegisterAction();

        /// <summary>
        /// 注销事件
        /// </summary>
        public abstract void UnRegisterAction();

        /// <summary>
        /// 浏览模式状态
        /// </summary>
        protected virtual void BrowserStatus()
        {
        }

        /// <summary>
        /// 编辑模式状态
        /// </summary>
        protected virtual void EditorStatus()
        {
        }

        public void Dispose()
        {
            this.UnRegisterAction();
            if (this.m_ContainerCtrl != null)
            {
                this.m_ContainerCtrl.Dispose();
                this.m_ContainerCtrl = null;
            }
        }
    }
}
